package com.bite.book.mapper;

import com.bite.book.model.BookInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:DELL
 * Date:2025-06-03
 * Time:17:31
 */
@Mapper
public interface BookMapper {
    //    插入图书
    @Insert("insert into book_info (book_name, author, count, price, publish, `status`)" +
            "values (#{bookName}, #{author}, #{count}, #{price}, #{publish}, #{status})")
    Integer insertBook(BookInfo bookInfo);//传的比较多，所以用整体对象接收

    //分页--去掉为0删除的，再根据id进行倒序排列
    @Select("select * from book_info where status != 0 order by id desc limit #{offset}, #{limit}")
    List<BookInfo> queryBookByPage(Integer offset, Integer limit);

    //获取图书总数
    @Select("select count(1) from book_info where status != 0")//0代表删除，不能查已经删除了的
    Integer count();

    //获取图书信息
    @Select("select * from book_info where id = #{bookId}")
    BookInfo queryBookById(Integer bookId);

    //更新图书--返回的是更新条数
    //用xml方式实现
    Integer updateBookById(BookInfo bookInfo);

    //批量删除图书
    Integer batchDeleteBookByIds(List<Integer> ids);//使用动态SQL写,用xml

}
